<?php
include("comm/config.php");
include("include/base.class.php");
date_default_timezone_set('PRC');


function fixlen($str,$len){
	$i = 0;    
  $tlen = 0;    
  $tstr = '';    
  while ($tlen < $len) {    
      $chr = mb_substr($str, $i, 1, 'utf8');    
      $chrLen = ord($chr) > 127 ? 2 : 1;    
      if ($tlen + $chrLen > $len) break;    
      $tstr .= $chr;    
      $tlen += $chrLen;    
      $i ++;    
  }    
  if ($tstr != $str) {    
      $tstr .= '......';    
  }    
  return htmlspecialchars($tstr,utf-8);
}
		

function dirReader($dir){
	$handle=opendir($dir);
	$i=0;
	while($file=readdir($handle))   {
		if   (($file!= ".")and($file!= ".."))   {
		$list[$i]=$file;
		$i=$i+1;
		}
	}
	closedir($handle);  
	return   $list;
}



function checkSql($str){

	//$str=trim($str);
 	//$str=strip_tags($str);
 	//$str=stripslashes($str);
 	//$str=addslashes($str);
 	//$str=rawurldecode($str);
 	//$str=quotemeta($str);
 	//$str=htmlspecialchars($str);
 	$str=preg_replace("/\+|\*|\`|\/|\-|\$|\#|\^|\!|\@|\%|\&|\~|\^|\[|\]|\'|\"|\<|\>|\=|\,|\;|\:/", "", $str);
 	//去除特殊符号+*`/-$#^~!@#$%&[]'"
 	//$str=preg_replace("//s/", "", $str);//去除空格、换行符、制表符
 	return $str;

}

function cutphoto($o_photo,$d_photo,$width,$height){ 
	$temp_img = imagecreatefromjpeg($o_photo); 
	$o_width  = imagesx($temp_img);                                //取得原图宽 
	$o_height = imagesy($temp_img);                                //取得原图高 	
	//判断处理方法 
	if($width>$o_width || $height>$o_height){        //原图宽或高比规定的尺寸小,进行压缩 	
		$newwidth=$o_width; 
		$newheight=$o_height; 	
		if($o_width>$width){ 
		        $newwidth=$width; 
		        $newheight=$o_height*$width/$o_width; 
		} 	
		if($newheight>$height){ 
		        $newwidth=$newwidth*$height/$newheight; 
		        $newheight=$height; 
		} 	
		//缩略图片 
		$new_img = imagecreatetruecolor($newwidth, $newheight);  
		imagecopyresampled($new_img, $temp_img, 0, 0, 0, 0, $newwidth, $newheight, $o_width, $o_height);  
		imagejpeg($new_img , $d_photo);                 
		imagedestroy($new_img); 	
	}else{                                                                                //原图宽与高都比规定尺寸大,进行压缩后裁剪 
	  if($o_height*$width/$o_width>$height){        //先确定width与规定相同,如果height比规定大,则ok 
	          $newwidth=$width; 
	          $newheight=$o_height*$width/$o_width; 
	          $x=0; 
	          $y=($newheight-$height)/2; 
	  }else{                                                                        //否则确定height与规定相同,width自适应 
	          $newwidth=$o_width*$height/$o_height; 
	          $newheight=$height; 
	          $x=($newwidth-$width)/2; 
	          $y=0; 
	  } 	
	  //缩略图片 
	  $new_img = imagecreatetruecolor($newwidth, $newheight);  
	  imagecopyresampled($new_img, $temp_img, 0, 0, 0, 0, $newwidth, $newheight, $o_width, $o_height);  
	  imagejpeg($new_img , $d_photo);                 
	  imagedestroy($new_img); 
	  	         
	  $temp_img = imagecreatefromjpeg($d_photo); 
	  $o_width  = imagesx($temp_img);                                //取得缩略图宽 
	  $o_height = imagesy($temp_img);                                //取得缩略图高 
	
	  //裁剪图片 
	  $new_imgx = imagecreatetruecolor($width,$height); 
	  imagecopyresampled($new_imgx,$temp_img,0,0,$x,$y,$width,$height,$width,$height); 
	  imagejpeg($new_imgx , $d_photo); 
	  imagedestroy($new_imgx); 
	} 
}

function head(){
	include 'content/header.php';
}

function footer(){
	include 'content/footer.php';
}

function alipay($order){
	$orders_id = $order;
	include 'alipay/alipayto.php';
}
?>